// [数据源] 接口
import { axios } from '@/utils/request';

/**
 * [数据源] 添加数据库连接
 * @params data
 * {
    {"databaseType":{"type":"string"}}
   }
 */
export function postDatahubDatasource(data) {
  return axios({
    method: 'post',
    url: 'datahub/datasource',
    data
  })
}

/**
 * [数据源] 更新数据库连接
 * @params data
 * {
    {"connectTimeout":{"description":"连接超时","type":"integer"}},
    {"databaseName":{"description":"数据库名","type":"string"}},
    {"databaseType":{"description":"数据库类型","type":"string"}},
    {"id":{"description":"主键","type":"integer"}},
    {"idleTimeout":{"description":"空闲连接时长","type":"integer"}},
    {"ip":{"description":"连接IP","type":"string"}},
    {"maxPoolSize":{"description":"最大连接数","type":"integer"}},
    {"minIdleSize":{"description":"最小空闲连接数","type":"integer"}},
    {"name":{"description":"连接名称","type":"string"}},
    {"password":{"description":"密码","type":"string"}},
    {"port":{"description":"连接端口","type":"integer"}},
    {"username":{"description":"用户名","type":"string"}}
   }
 */
export function putDatahubDatasource(data) {
  return axios({
    method: 'put',
    url: 'datahub/datasource',
    data
  })
}

/**
 * [数据源] 删除数据库连接
 * @params params
 * {
    {"id":{"required":true,"type":"integer"}}
   }
 */
export function deleteDatahubDatasource(params) {
  return axios({
    method: 'delete',
    url: 'datahub/datasource',
    params
  })
}

/**
 * [数据源] 测试数据库连接
 * @params params
 * {
    {"databaseType":{"required":false,"type":"string"}},
    {"ip":{"required":false,"type":"string"}},
    {"port":{"required":false,"type":"integer"}},
    {"databaseName":{"required":false,"type":"string"}},
    {"username":{"required":false,"type":"string"}},
    {"password":{"required":false,"type":"string"}},
    {"connectTimeout":{"required":false,"type":"integer"}},
    {"maxPoolSize":{"required":false,"type":"integer"}},
    {"minIdleSize":{"required":false,"type":"integer"}},
    {"idleTimeout":{"required":false,"type":"integer"}}
   }
 */
export function getDatahubDatasourceConnect(params) {
  return axios({
    method: 'get',
    url: 'datahub/datasource/connect',
    params
  })
}

/**
 * [数据源] 获取所有数据源列表
 * @params params
 * {
    {"name":{"required":false,"type":"string"}},
    {"databaseType":{"required":false,"type":"string"}},
    {"ip":{"required":false,"type":"string"}},
    {"pageNo":{"required":false,"type":"integer"}},
    {"pageSize":{"required":false,"type":"integer"}}
   }
 */
export function getDatahubDatasourceList(params) {
  return axios({
    method: 'get',
    url: 'datahub/datasource/list',
    params
  })
}

/**
 * [数据源] 分页获取所有数据源列表
 * @params params
 * {
    {"name":{"required":false,"type":"string"}},
    {"databaseType":{"required":false,"type":"string"}},
    {"ip":{"required":false,"type":"string"}},
    {"pageNo":{"required":false,"type":"integer"}},
    {"pageSize":{"required":false,"type":"integer"}}
   }
 */
export function getDatahubDatasourcePage(params) {
  return axios({
    method: 'get',
    url: 'datahub/datasource/page',
    params
  })
}

/**
 * [数据源] 查询指定数据源被关联信息
 * @params params
 * {
    {"id":{"required":true,"type":"integer"}}
   }
 */
export function getDatahubDatasourceRelation(params) {
  return axios({
    method: 'get',
    url: 'datahub/datasource/relation',
    params
  })
}

/**
 * [数据源] 获取指定数据源下的schema集合
 * @params params
 * {
    {"datasourceId":{"required":true,"type":"integer"}}
   }
 */
export function getDatahubDatasourceSchemas(params) {
  return axios({
    method: 'get',
    url: 'datahub/datasource/schemas',
    params
  })
}

/**
 * 数据库连接主动校验
 * @params params
 * {
    {"id":{"required":false,"type":"integer"}},
    {"field":{"required":false,"type":"string"}},
    {"value":{"required":false,"type":"object"}}
   }
 */
export function getDatahubDatasourceVerification(params) {
  return axios({
    method: 'get',
    url: 'datahub/datasource/verification',
    headers: { validate: true },
    params
  })
}